package org.example.springboot_threadpool_demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAsync
@EnableScheduling
@SpringBootApplication
//@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class SpringbootThreadpoolDemoApplication {

    @Autowired
    AsyncService asyncService;

    @Autowired
    @Qualifier("taskExecutor")
    ThreadPoolTaskExecutor taskExecutor;

    public static void main(String[] args) {
        SpringApplication.run(SpringbootThreadpoolDemoApplication.class, args);
    }

    @GetMapping("/th1")
    public String th1() {
        return "thread th1: " + Thread.currentThread().getName();
    }

    @GetMapping("/async1")
    public String async1() {
        asyncService.asyncMethod();
        return "async1 thread: " + Thread.currentThread().getName();
    }

    @GetMapping("/async2")
    public String async2() {
        asyncService.asyncMethod2();
        return "async2 thread: " + Thread.currentThread().getName();
    }

    @GetMapping("/taskExecutorInfo")
    public String taskExecutorInfo() {
        return "pool size: " + taskExecutor.getMaxPoolSize();
    }
}
